//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Data;
using System.Windows.Media;

namespace OpenLS.Drawing.UI.Internals
{
    class PresetLineDashValueToStrokeDashArrayConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
            PresetLineDashValue v = (PresetLineDashValue) value;
            var array = GetArray(v);
            if (array == null)
                return null;
            return new DoubleCollection(array);
            
        }

        private static double[] GetArray(PresetLineDashValue presetLineDashValue)
        {
            switch (presetLineDashValue)
            {
                case PresetLineDashValue.Dash:
                    return new[] { 4.0, 4 };
                case PresetLineDashValue.DashDot:
                    return new[] { 4.0, 4, 1, 4 };
                case PresetLineDashValue.Solid:
                    return null;
                case PresetLineDashValue.Dot:
                    return new[] { 1.0, 1.0 };
                case PresetLineDashValue.LargeDash:
                    return new[] { 7.0, 4 };
                case PresetLineDashValue.LargeDashDot:
                    return new[] { 7.0, 4, 1, 4 };
                case PresetLineDashValue.LargeDashDotDot:
                    return new[] { 7.0, 4, 1, 4, 1, 4 };
                case PresetLineDashValue.SystemDash:
                    return new[] { 3.0, 2 };
                case PresetLineDashValue.SystemDashDot:
                    return new[] { 3.0, 2, 1, 2 };
                case PresetLineDashValue.SystemDashDotDot:
                    return new[] { 6.0, 4, 1, 4, 1, 4 };
                case PresetLineDashValue.SystemDot:
                    return new[] { 1.0, 1 };

            }
            throw new NotImplementedException();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}